﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.IO;

namespace MinConsole.Conf
{
    public sealed class AppInstSettings : MinConsole.Gaf.Model.AppInstSettings
        {

            #region SingletonPattern
        
            /// <summary>
            /// <source>http://www.yoda.arachsys.com/csharp/singleton.html</source>
            /// </summary>
            public AppInstSettings():base()
            {
                try
                {

                    string strIniFile = MinConsole.Gaf.IO.FileUtility.CreateProcessDefaultIniFile();
                    MinConsole.IniParser.FileIniDataParser parser = new MinConsole.IniParser.FileIniDataParser();
                    MinConsole.IniParser.IniData parsedData = parser.LoadFile(strIniFile);
                    base.LoadDataFromIniFile(parsedData, "GeneralConfiguration");
                }
                catch (Exception ex)
                {
                    #region Msg failed to initialize ini file
                    string strMsgToEndUser = @" Failed to initialize the data from the ini file.  Please chech you ini file settings: You could use the following template:
COPYPASTE START: 

;This section contais the stored procedures to run 
;We use human counting the first item is 1 , the second 2 , the third 3 e.g. not Programmers ; ) 
;format: DataSource1=DataSource1Name
;format: DataSource2=DataSource2Name
[DataSourcesToRun]
DataSource1=POC_DEV
DataSource2=POC_DEV

;This section contais the stored procedures to run 
;We use human counting the first item is 1 , the second 2 , the third 3 e.g. not Programmers ; ) 
;format: StoredProcedure1=StoredProcedure1Name
;format: StoredProcedure2=StoredProcedure2Name
[DataSource1StoredProcsToRun]
StoredProcedure1=procDeleteMe_BugSelectAll
StoredProcedure2=procDeleteMe_BugSelectAll1

[DataSource2StoredProcsToRun]
StoredProcedure1=procDeleteMe_BugSelectAll2
StoredProcedure2=procDeleteMe_BugSelectAll3


;Fill in here the parameters for the first stored procedure
[DataSource1StoredProcedure1]
Name=procDeleteMe_BugSelectAll


;Fill in here the parameters for the first stored procedure
[DataSource1StoredProcedure2]
Name=procDeleteMe_BugSelectAll1


;Fill in here the parameters for the first stored procedure
[DataSource2StoredProcedure1]
Name=procDeleteMe_BugSelectAll2


;Fill in here the parameters for the first stored procedure
[DataSource2StoredProcedure2]
Name=procDeleteMe_BugSelectAll3


;This section provides the general configuration of the application
[GeneralConfiguration] 
;Where the log file will be situated
AppLoginName = ysg
AppLoginPass = pass
AppName = MinConsole
ConnectionStringTemplate = Data Source={0:G}¤Initial Catalog={1:G}¤Persist Security Info=False¤User ID={2:G}¤Password={3:G}¤MultipleActiveResultSets=True
CultureInfo = fi-FI
CultureNameUnderscored = fi_FI
CurrencyDecimalDigits = 2
DbHostNameAndInstance = hostName\POC_QA
DbName = POC_DEV
DebugDir = E:\nelle\nelle.9.2.0\sfw\src\MinConsole\MinConsole.0.5.0\MinConsole\bin\Release
DefaultLoginName = ysg
DefaultLoginPass = pass
DefaultRDBMS = 1
EncryptionAlgorithm = None
FlagEncryptErrorMessages = 1
FlagShowDbSwitcher = 1
LogLevel = 4
LogOutput = 4
NumberDecimalDigits = 2
NumberDecimalSeparator =  
NumberGroupSeparator =  
NumberOfDatabases = 1
LogDir = E:\nelle\nelle.9.2.0\sfw\src\MinConsole\MinConsole.0.5.0\MinConsole\bin\Release
LogFileNameTimePattern = yyyy.MM.dd
;what will be the name of the log file 
LogFileNameSuffix = MinConsole.log	
LogMessageSuffix = yyyy.MM.dd - hh.mm.ss --- 
;Whether or not to log to a file 1 will log to a file , 0 will NOT log to a file
LogToFile=1 
; Whether or not to log to a console 1 will log , 0 will not
LogToConsole=1
; whether or not to log to a database 1 will log , 0 will not 
LogToDb=1
; if we debug to a file what will be the debug log file name 
DebugFileNameSuffix = MinConsole.debug.log
; to which directory to the put the extracted files 
DataExtractDir=E:\nelle\nelle.9.2.0\sfw\src\MinConsole\MinConsole.0.5.0\MinConsole\bin\Release
; from how-many database to retrieve data 
NumberOfDataSourcesToRun=2


[DataSource1]
;The id of this datasource
DataSourceId=1		
;
RunId=1				;the number to run to 
Name=POC_DEV
DataSourceTypeId = 1 ; 1=Database
CurrencyDecimalDigits = 2
DbHostNameAndInstance = hostName\POC_QA
DbName = POC_DEV
DebugDir = E:\nelle\nelle.9.2.0\sfw\src\MinConsole\MinConsole.0.5.0\MinConsole\bin\Release
LoginName = ysg
LoginPass = pass
DefaultRDBMS = 1
NumberOfStoredProceduresToRun=2
DataExtractDir=E:\nelle\nelle.9.2.0\sfw\src\MinConsole\MinConsole.0.5.0\MinConsole\bin\Release
ConnectionStringTemplate = Data Source={0:G}¤Initial Catalog={1:G}¤Persist Security Info=False¤User ID={2:G}¤Password={3:G}¤MultipleActiveResultSets=True
TokenDelimiterAsciiNumber = 44		;This is the ASCII number of the token delimiter to use in the csv file
RowEndAsciiNumber = 13 							;This is the ASCII number of the token delimiter to use in the csv file
FlagQuoteTokens = 1 ; whether or not to qote tokens in the extract files 



[DataSource2]
;WHERE THE LOG FILE WILL BE SITUATED
DataSourceId=1		
RunId=1				;the number to run to 
Name=POC_DEV
DataSourceTypeId = 1 ; 1=Database
CurrencyDecimalDigits = 2
DbHostNameAndInstance = hostName\POC_QA
DbName = POC_DEV
DebugDir = E:\nelle\nelle.9.2.0\sfw\src\MinConsole\MinConsole.0.5.0\MinConsole\bin\Release
LoginName = ysg
LoginPass = pass
DefaultRDBMS = 1
NumberOfStoredProceduresToRun=2
DataExtractDir=E:\nelle\nelle.9.2.0\sfw\src\MinConsole\MinConsole.0.5.0\MinConsole\bin\Release
ConnectionStringTemplate = Data Source={0:G}¤Initial Catalog={1:G}¤Persist Security Info=False¤User ID={2:G}¤Password={3:G}¤MultipleActiveResultSets=True
TokenDelimiterAsciiNumber = 44		;This is the ASCII number of the token delimiter to use in the csv file
RowEndAsciiNumber = 13 							;This is the ASCII number of the token delimiter to use in the csv file




COPYPASTEEND"; 
                    #endregion Msg failed to initialize ini file 
                    Console.WriteLine(strMsgToEndUser);
                    Console.WriteLine(ex.Message); 
                
                }


            }//eof const



            /// <summary>
            /// This provides the Singleton 
            /// </summary>
            public static AppInstSettings Instance
            {
                get
                {
                       return Nested.instance;
                } //eof get 

            } //eof prop

            class Nested
            {
                // Explicit static constructor to tell C# compiler
                // not to mark type as before field init
                static Nested()
                {
                }

                internal static readonly AppInstSettings instance = new AppInstSettings();
            } //eof class 

            #endregion SingletonPattern

        } //eof class AppInstSettings
} //eof namespace 
